package br.ufrj.dcc.trabxml.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import br.ufrj.dcc.trabxml.manager.BookManager;
import br.ufrj.dcc.trabxml.view.FormMain;

public class DeleteBook implements ActionListener {
    
    private FormMain form = null;

    public DeleteBook(FormMain form) {
        this.form = form;
    }    

    public void actionPerformed(ActionEvent e) {
        if (JOptionPane.showConfirmDialog(form, "Deseja realmente excluir este livro?","Excluir?",JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
            return;
        }
        try {
            BookManager manager = new BookManager();
            manager.deleteBook(form.getDeleteISBN());         
            form.setDeleteISBN(null);
            JOptionPane.showMessageDialog(form, "Livro exclu\u00eddo com sucesso.", "Info",
                    JOptionPane.INFORMATION_MESSAGE);               
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(form, ex.getMessage(), "Erro",
                    JOptionPane.ERROR_MESSAGE);
        }
    }

}
